Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Sep 19, 2025

This PR attempts to address Issue #8172 by implementing an auto-cleanup feature for task history.

Summary

Implements automatic cleanup of task history to prevent disk space from expanding rapidly when checkpoints are enabled. The feature is disabled by default to maintain backward compatibility.

Changes

  • ✅ Added configuration settings for auto-cleanup (enabled, maxCount, maxDiskSpaceMB, maxAgeDays)
  • ✅ Created TaskHistoryCleanupService to handle cleanup logic
  • ✅ Implemented cleanup by count, disk space, and age thresholds
  • ✅ Integrated cleanup service into ClineProvider with idle-time execution
  • ✅ Added comprehensive tests for cleanup service
  • ✅ Protected tasks from current workspace from deletion

Configuration

The feature can be configured through VSCode settings:

  • taskHistoryAutoCleanupEnabled: Enable/disable auto-cleanup (default: false)
  • taskHistoryMaxCount: Maximum number of tasks to keep (default: 100)
  • taskHistoryMaxDiskSpaceMB: Maximum disk space in MB (default: 1024)
  • taskHistoryMaxAgeDays: Maximum age in days (default: 7)

Testing

All tests pass including:

  • New cleanup service tests covering all scenarios
  • Existing ClineProvider tests confirming no regression

Fixes #8172

Feedback and guidance are welcome!


Important

Introduces auto-cleanup for task history in ClineProvider using TaskHistoryCleanupService, configurable via VSCode settings, with comprehensive tests.

  • Behavior:
    • Adds auto-cleanup for task history in ClineProvider and TaskHistoryCleanupService.
    • Cleanup based on count, disk space, and age thresholds.
    • Protects tasks from the current workspace from deletion.
    • Configurable via VSCode settings: taskHistoryAutoCleanupEnabled, taskHistoryMaxCount, taskHistoryMaxDiskSpaceMB, taskHistoryMaxAgeDays.
  • Implementation:
    • Introduces TaskHistoryCleanupService for cleanup logic.
    • Integrates cleanup service into ClineProvider with idle-time execution.
    • Updates global-settings.ts to include new configuration options.
  • Testing:
    • Comprehensive tests for TaskHistoryCleanupService in TaskHistoryCleanupService.spec.ts.
    • Ensures cleanup logic handles all scenarios and errors gracefully.

This description was created by Ellipsis for d4a370e. You can customize this summary. It will automatically update as commits are pushed.

- Add configuration settings for auto-cleanup (enabled, maxCount, maxDiskSpaceMB, maxAgeDays)
- Create TaskHistoryCleanupService to handle cleanup logic
- Implement cleanup by count, disk space, and age thresholds
- Integrate cleanup service into ClineProvider with idle-time execution
- Add comprehensive tests for cleanup service
- Cleanup runs automatically when thresholds are exceeded
- Protects tasks from current workspace from deletion
- Default settings: disabled, 100 tasks max, 1GB disk space, 7 days age

Fixes #8172
@roomote roomote bot requested review from cte, jr and mrubens as code owners September 19, 2025 02:10
@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. enhancement New feature or request labels Sep 19, 2025
for (const task of tasksToDelete) {
try {
// Calculate size before deletion for reporting
if (result.freedSpaceMB === 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider always accumulating the freed space for each deleted task instead of conditionally adding it only when freedSpaceMB is zero. This ensures the reported freedSpaceMB reflects the total space freed from all deletion criteria (age, count, disk space), not just the first task.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Sep 19, 2025
Copy link
Contributor Author

@roomote roomote bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrote this code 5 minutes ago and already found 6 things wrong with it.

// Check if cleanup should be triggered
if (this.taskHistoryCleanupService.shouldTriggerCleanup(taskHistory ?? [], config)) {
// Run cleanup in the background during idle time
setTimeout(async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intentional? Using a 5-second setTimeout could cause race conditions if multiple tasks complete in quick succession. Each task update would schedule its own cleanup, potentially leading to multiple concurrent cleanup operations.

Consider using a debounced queue or mutex pattern to ensure only one cleanup runs at a time.

for (const task of tasksToDelete) {
try {
// Calculate size before deletion for reporting
if (result.freedSpaceMB === 0) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a potential issue here - if calculating the task size fails, freedSpaceMB remains 0, which gives incorrect metrics. We should calculate the size for all tasks to be deleted upfront.

Could we move the size calculation outside the try-catch or ensure we always calculate it?

* Calculates the total disk space used by all tasks in MB
*/
private async calculateTotalTaskSize(taskHistory: HistoryItem[]): Promise<number> {
let totalSizeMB = 0
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calculating total disk space by iterating through all tasks is expensive, especially since we're already checking disk space during the cleanup process. Could we consider:

  1. Only calculating when maxDiskSpaceMB is configured
  2. Implementing a cache that updates after each task operation
  3. Using filesystem metadata if available

This would significantly improve performance for users with large task histories.

openRouterImageGenerationSelectedModel,
openRouterUseMiddleOutTransform,
featureRoomoteControlEnabled,
taskHistoryAutoCleanupEnabled: taskHistoryAutoCleanupEnabled ?? false,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default values here (100 tasks, 1000MB, 7 days) might be too aggressive for some users. Have we considered:

  1. More conservative defaults (e.g., 200 tasks, 2000MB, 14 days)?
  2. Making these workspace-specific rather than global?
  3. Adding a first-run prompt to let users configure their preferences?

This could prevent accidental data loss for users who don't realize cleanup is happening.

vi.useRealTimers()
})

describe("performCleanup", () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're missing test coverage for:

  1. Concurrent cleanup attempts (multiple tasks finishing simultaneously)
  2. Edge case where a task has no timestamp
  3. Cleanup failure recovery (partial cleanup success)
  4. Tasks with corrupted/missing directories

Could we add these scenarios to ensure robustness?

- Add safety check for globalStorageUri before initializing TaskHistoryCleanupService
- Prevents test failures when globalStorageUri is not mocked in test context
@roomote roomote bot mentioned this pull request Sep 19, 2025
2 tasks
@daniel-lxs
Copy link
Member

This PR creates new settings that are not exposed in the UI and I think this should be configurable.

@daniel-lxs daniel-lxs closed this Sep 23, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Sep 23, 2025
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Sep 23, 2025
@daniel-lxs daniel-lxs deleted the feat/auto-cleanup-task-history branch September 23, 2025 22:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

[ENHANCEMENT] Auto Clean Task History

4 participants